package com.test.storage.controller;

import com.test.storage.entity.Storage;
import com.test.storage.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/storage")
public class StorageController {

    private final StorageService storageService;

    @Autowired
    public StorageController(StorageService storageService) {
        this.storageService = storageService;
    }


    @PostMapping
    public void create(Storage storage) {
        storageService.save(storage);
    }

    @PutMapping("/deduct")
    public void deduct(@RequestParam("commodityCode") String commodityCode,
                       @RequestParam("count") Integer count) {
        storageService.deduct(commodityCode, count);
    }
}
